package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsTerminalStatistics;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsTerminalStatisticsDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-01-17 10:16:47
 */
public class LbsTerminalStatisticsConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsTerminalStatisticsConverts.class);

    public static List<LbsTerminalStatisticsDTO> convert(List<LbsTerminalStatistics> lbsTerminalStatisticsList) {
        if (CollectionUtils.isEmpty(lbsTerminalStatisticsList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsTerminalStatisticsDTO> lbsTerminalStatisticsListResult = Lists.newArrayList();
        for (LbsTerminalStatistics lbsTerminalStatistics : lbsTerminalStatisticsList) {
            lbsTerminalStatisticsListResult.add(convert(lbsTerminalStatistics));
        }
        return lbsTerminalStatisticsListResult;
    }

    public static LbsTerminalStatisticsDTO convert(LbsTerminalStatistics lbsTerminalStatistics) {
        try {
            return BeanUtils.copy(lbsTerminalStatistics, LbsTerminalStatisticsDTO.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalStatistics到LbsTerminalStatisticsDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalStatistics到LbsTerminalStatisticsDTO转换失败", e);
        }
    }

    public static LbsTerminalStatistics convert(LbsTerminalStatisticsDTO lbsTerminalStatisticsDTO) {
        try {
            return BeanUtils.copy(lbsTerminalStatisticsDTO, LbsTerminalStatistics.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalStatisticsDTO到LbsTerminalStatistics转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalStatisticsDTO到LbsTerminalStatistics转换失败", e);
        }
    }
}